home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / JToolTip.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  186 lines

  1. /*
  2.  * %W% %E%
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21.  
  22. package com.sun.java.swing;
  23. import com.sun.java.swing.plaf.*;
  24. import com.sun.java.accessibility.*;
  25.  
  26.  
  27. /**
  28.  * Used to display a "Tip" for a Component. Typically components provide api
  29.  * to automate the process of using ToolTips. For example, any Swing component
  30.  * can use the JComponent <code>setToolTipText</code> method to specify the text
  31.  * for a standard tooltip. A component that wants to create a custom ToolTip
  32.  * display can override JComponent's <code>createToolTip</code> method and use
  33.  * a subclass of this class.
  34.  * <p>
  35.  * For the keyboard keys used by this component in the standard Look and
  36.  * Feel (L&F) renditions, see the
  37.  * <a href="doc-files/Key-Index.html#JToolTip">JToolTip</a> key assignments.
  38.  * <p>
  39.  * See <a href="http://java.sun.com/docs/books/tutorial/ui/swing/tooltip.html">How to Use Tool Tips</a>
  40.  * in <a href="http://java.sun.com/Series/Tutorial/index.html"><em>The Java Tutorial</em></a>
  41.  * for further documentation.
  42.  * <p>
  43.  * Warning: serialized objects of this class will not be compatible with
  44.  * future swing releases.  The current serialization support is appropriate
  45.  * for short term storage or RMI between Swing1.0 applications.  It will
  46.  * not be possible to load serialized Swing1.0 objects with future releases
  47.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  48.  * baseline for the serialized form of Swing objects.
  49.  *
  50.  * @see JComponent#setToolTipText
  51.  * @see JComponent#createToolTip
  52.  * @version %I% %G%
  53.  * @author Dave Moore
  54.  * @author Rich Shiavi
  55.  */
  56. public class JToolTip extends JComponent implements Accessible {
  57.     String tipText;
  58.     JComponent component;
  59.  
  60.     /** Creates a tool tip. */
  61.     public JToolTip() {
  62.         updateUI();
  63.     }
  64.  
  65.     /**
  66.      * Returns the L&F object that renders this component.
  67.      *
  68.      * @return the ToolTipUI object that renders this component
  69.      */
  70.     public ToolTipUI getUI() {
  71.         return (ToolTipUI)ui;
  72.     }
  73.  
  74.     /**
  75.      * Notification from the UIFactory that the L&F has changed. 
  76.      * Called to replace the UI with the latest version from the 
  77.      * UIFactory.
  78.      *
  79.      * @see JComponent#updateUI
  80.      */
  81.     public void updateUI() {
  82.         setUI((ToolTipUI)UIManager.getUI(this));
  83.     }
  84.  
  85.  
  86.     /**
  87.      * Returns the name of the L&F class that renders this component.
  88.      *
  89.      * @return "ToolTipUI"
  90.      * @see JComponent#getUIClassID
  91.      * @see UIDefaults#getUI
  92.      */
  93.     public String getUIClassID() {
  94.         return "ToolTipUI";
  95.     }
  96.  
  97.  
  98.     /**
  99.      * Sets the text to show when the tool tip is displayed.
  100.      *
  101.      * @param tipText the String to display
  102.      */
  103.     public void setTipText(String tipText) {
  104.         this.tipText = tipText;
  105.     }
  106.  
  107.     /**
  108.      * Returns the text that is shown when the tool tip is displayed.
  109.      *
  110.      * @return the String that is displayed
  111.      */
  112.     public String getTipText() {
  113.         return tipText;
  114.     }
  115.  
  116.     /**
  117.      * Specifies the component that the tooltip describes.
  118.      *
  119.      * @see JComponent#createToolTip
  120.      */
  121.     public void setComponent(JComponent c) {
  122.         component = c;
  123.     }
  124.  
  125.     /**
  126.      * @return the component that the tooltip describes.
  127.      *
  128.      * @see JComponent#createToolTip
  129.      */
  130.     public JComponent getComponent() {
  131.         return component;
  132.     }
  133.  
  134. /////////////////
  135. // Accessibility support
  136. ////////////////
  137.  
  138.     /**
  139.      * Get the AccessibleContext associated with this JComponent
  140.      *
  141.      * @return the AccessibleContext of this JComponent
  142.      */
  143.     public AccessibleContext getAccessibleContext() {
  144.         if (accessibleContext == null) {
  145.             accessibleContext = new AccessibleJToolTip();
  146.         }
  147.         return accessibleContext;
  148.     }
  149.  
  150.     /**
  151.      * The class used to obtain the accessible role for this object.
  152.      * <p>
  153.      * Warning: serialized objects of this class will not be compatible with
  154.      * future swing releases.  The current serialization support is appropriate
  155.      * for short term storage or RMI between Swing1.0 applications.  It will
  156.      * not be possible to load serialized Swing1.0 objects with future releases
  157.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  158.      * baseline for the serialized form of Swing objects.
  159.      */
  160.     protected class AccessibleJToolTip extends AccessibleJComponent {
  161.  
  162.         /**
  163.          * Get the accessible description of this object.
  164.          *
  165.          * @return a localized String describing this object.
  166.          */
  167.         public String getAccessibleDescription() {
  168.             if (accessibleDescription != null) {
  169.                 return accessibleDescription;
  170.             } else {
  171.                 return getTipText();
  172.             }
  173.         }
  174.  
  175.         /**
  176.          * Get the role of this object.
  177.          *
  178.          * @return an instance of AccessibleRole describing the role of the 
  179.          * object
  180.          */
  181.         public AccessibleRole getAccessibleRole() {
  182.             return AccessibleRole.TOOL_TIP;
  183.         }
  184.     }
  185. }
  186.